<template>
	<view :style="theme">
		<view class="jg"></view>
		<view class="content">
			<radio-group v-if="items.length != 0">
				<label class="box" v-for="(item, index) in items" :key="index" @click="radioChange(item)">
					<view class="box_left">
						<text v-if="item.remainNumCount && item.remainNumCount!=0" class="one">剩余次数</text>
						<text v-if="item.remainNumCount && item.remainNumCount!=0" class="limit-1-line num">{{ item.remainNumCount }}</text>
						<text v-if="item.indate" class="time">购买{{ item.indate }}天内有效</text>
						<view class="y_t"></view>
						<view class="y_b"></view>
					</view>
					<view class="box_right">
						<view class="box_right_wz">
							<text>{{ item.name }}</text>
							<text v-if="item.projectName">{{ item.projectName }}</text>
							<text>有效期至：{{ item.validityEndTime }}</text>
						</view>
						<radio class="box_right_radio" :value="item.id" :checked="item.checked" />
					</view>
				</label>
			</radio-group>
		</view>
		<view v-if="items.length === 0" class="no_list">
			<image :src="imgHost+'/default_wutaocan.png'" class="wu"></image>
			<view class="ts">目前暂无可用套餐</view>
			<view class="zy">如在美团、抖音购买的卡券，可以选择团购兑换 或者直接购买套餐</view>
			<view class="flex flex_between btns">
				<view class="a" @click="jump3('/pages/goup/index')">
					<image :src="imgHost+'/ic_duihuan.png'"></image>团购兑换
				</view>
				<view class="b" @click="jump2('/pages/setmeal/index')">购买套餐</view>
			</view>
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				id: '',
				mealsMemberId: '',
				items: []
			}
		},
		onLoad(ops) {
			this.id = ops.id
			this.zfType = ops.zfType
			this.mealsMemberId = ops.mealsMemberId
		},
		onShow() {
			this.getList()
		},
		methods: {
			jump(url, params, a) {
				this.$app.jump(url, params, a);
			},
			jump2(url, params, a) {
				this.$app.jump2(url, params, a);
			},
			jump3(url, params, a) {
				this.$app.jump3(url, params, a);
			},
			radioChange(e) {
				let mealsMemberId = e.id
				let mealsMemberName = ''
				if (this.mealsMemberId == e.id) {
					mealsMemberId = ''
				} else {
					mealsMemberName = e.name
				}
				var pages = getCurrentPages();
				var prevPage = pages[pages.length - 2];
				// #ifdef H5
				prevPage.$vm.mealsMemberId = mealsMemberId;
				prevPage.$vm.mealsMemberName = mealsMemberName;
				// #endif
				// #ifdef MP
				prevPage.setData({
					mealsMemberId,
					mealsMemberName
				});
				// #endif
				uni.navigateBack()
			},
			getList() {
				this.$app.ajax({
					data: {
						userId: this.userInfo.id,
						param: {
							memberId: this.userInfo.id,
							orderId: this.id,
						}
					},
					api: this.$api.getMealsReserveCard(),
				}).then((res) => {
					if (res.errorCode === '000000') {
						let arr = res.record || []
						arr.forEach((e) => {
							if (e.id == this.mealsMemberId) {
								e.checked = true
							} else {
								e.checked = false
							}
						})
						this.items = arr
					}
				}).catch(() => {})
			},
		}

	}
</script>
<style>
	page {
		background: #ffffff;
	}
</style>
<style scoped lang="scss">
	.jg {
		background: $bjColor;
		height: 20rpx;
	}

	radio .wx-radio-input {
		border-radius: 50%;
		width: 24px;
		height: 24px;
	}

	radio .wx-radio-input {
		background: #ffffff;
	}

	radio .wx-radio-input.wx-radio-input-checked {
		background: $color;
		border: none;
	}

	radio .wx-radio-input.wx-radio-input-checked::before {
		background-color: $color;
	}

	.content {
		padding: 30rpx;
		box-sizing: border-box;
	}

	.box {
		display: flex;
		background: #ffffff;
		margin-bottom: 24rpx;
		height: 180rpx;
		border-radius: 10rpx;
		overflow: hidden;
	}

	.box_left {
		width: 30%;
		padding: 30rpx 0;
		box-sizing: border-box;
		position: relative;
		display: flex;
		align-items: center;
		justify-content: center;
		flex-direction: column;
		background: $color;
		box-shadow: inset 0px 2px 4px 0px $bjtm;
	}

	.y_t {
		width: 30rpx;
		height: 30rpx;
		background: $bjColor;
		border-radius: 50%;
		position: absolute;
		right: -15rpx;
		top: -15rpx;
	}

	.y_b {
		width: 30rpx;
		height: 30rpx;
		background: $bjColor;
		border-radius: 50%;
		position: absolute;
		right: -15rpx;
		bottom: -15rpx;
	}

	.box_left text.one {
		font-size: 24rpx;
		font-weight: 400;
		color: rgba(255, 255, 255, 0.9);
	}

	.box_left text.num {
		font-size: 44rpx;
		font-weight: 500;
		color: #FFFFFF;
	}

	.box_left text.time {
		font-size: 22rpx;
		font-weight: 400;
		color: rgba(255, 255, 255, 0.9)
	}

	.box_right {
		flex: 1;
		padding: 30rpx;
		box-sizing: border-box;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.box_right_wz {
		width: 350rpx;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
	}

	.box_right_wz text:nth-child(1) {
		font-size: 30rpx;
		font-weight: 500;
		color: #222222;
	}

	.box_right_wz text:nth-child(2) {
		font-size: 24rpx;
		font-weight: 400;
		color: #333333;
		margin: 10rpx 0;
	}

	.box_right_wz text:nth-child(3) {
		font-size: 24rpx;
		font-weight: 400;
		color: #666666;
	}

	.box_right_radio {
		flex: 1;
		text-align: right;
	}

	.no_list {
		width: 630rpx;
		box-sizing: border-box;
		margin: 0 auto;
		display: flex;
		justify-content: center;
		align-items: center;
		flex-direction: column;
		height: 75vh;

		.wu {
			width: 360rpx;
			height: 188rpx;
		}

		.ts {
			font-size: 36rpx;
			font-family: PingFangSC-Semibold, PingFang SC;
			font-weight: 600;
			color: #222222;
			line-height: 1;
			margin-top: 60rpx;
		}

		.zy {
			width: 504rpx;
			height: 80rpx;
			font-size: 24rpx;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			margin: 30rpx auto 80rpx;
			color: #999999;
			line-height: 40rpx;
			text-align: center;
		}

		.btns {
			width: 100%;

			view {
				width: 304rpx;
				line-height: 88rpx;
				text-align: center;
				border-radius: 50rpx;
				border: 1rpx solid $color;
				font-size: 30rpx;
				font-family: PingFangSC-Medium, PingFang SC;
				font-weight: 500;
				width: 304rpx;
				height: 88rpx;
				border-radius: 50rpx;

				&.a {
					color: $color;

					image {
						width: 70rpx;
						height: 44rpx;
						vertical-align: middle;
						margin-right: 8rpx;
					}
				}

				&.b {
					color: #fff;
					background-color: $color;
				}
			}

		}
	}
</style>